#include <iostream>
#include <unistd.h>
#include <signal.h>

void handler(int sig)
{
    std::cout << "get sig: " << sig << std::endl;
}

int main()  
{
    signal(SIGINT, handler);//自定义2号信号的行为
    while (true)
    {
        std::cout << "pid: " << getpid() << std::endl;
        sleep(1);
    }

    return 0;
}